package com.ibiaoke.system.service;

import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.consts.CommonConsts;
import com.ibiaoke.common.utils.AssertUtils;
import com.ibiaoke.system.dao.TopicPageDao;
import com.ibiaoke.system.entity.TopicPage;
import com.ibiaoke.system.entity.vo.TopicPageVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class TopicPageServiceImpl implements TopicPageService {

    @Autowired
    private TopicPageDao topicPageDao;

    /**
     * 保存专题活动页
     * @param topicPageVO
     * @return
     */
    @Override
    public int saveTopicPage(TopicPageVO topicPageVO) {
        TopicPage topicPage = new TopicPage();
        BeanUtils.copyProperties(topicPageVO, topicPage);
        topicPage.setCreateTime(new Date());
        topicPage.setUpdateTime(new Date());
        topicPage.setDelStatus(CommonConsts.NO);
        return topicPageDao.insertSelective(topicPage);
    }

    /**
     * 修改专题活动页
     * @param topicPageVO
     * @return
     */
    @Override
    public int updateTopicPage(TopicPageVO topicPageVO) {
        AssertUtils.notNull(topicPageVO.getTopicPageId(), "专题id不能为空");
        TopicPage topicPage = new TopicPage();
        BeanUtils.copyProperties(topicPageVO, topicPage);
        topicPage.setUpdateTime(new Date());
        return topicPageDao.updateByPrimaryKeySelective(topicPage);
    }

    /**
     * 查询正常的专题活动页
     * @param page
     * @return
     */
    @Override
    public List<TopicPage> listTopicPage(Integer position,Integer showStatus,Page page) {
        return topicPageDao.listTopicPage(position,showStatus,page);
    }

    /**
     * 获取专题活动页详情
     * @param topicPageId
     * @return
     */
    @Override
    public TopicPage getTopicPage(Integer topicPageId) {
        AssertUtils.notNull(topicPageId, "专题活动页Id不能为空");
        return (TopicPage)topicPageDao.selectByPrimaryKey(topicPageId);
    }


    /**
     * 删除专题活动页
     * @param topicPageId
     * @return
     */
    @Override
    public int deleteTopicPage(Integer topicPageId) {
        AssertUtils.notNull(topicPageId, "专题活动页Id不能为空");
        TopicPage topicPage = new TopicPage();
        topicPage.setUpdateTime(new Date());
        topicPage.setTopicPageId(topicPageId);
        topicPage.setDelStatus(CommonConsts.YES);
        return topicPageDao.updateByPrimaryKeySelective(topicPage);
    }


}
